<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SystemRegion extends Model
{
    use SoftDeletes;

    protected $table = 'system_regions';

    /**
     * 定义主键
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 禁止批量赋值的字段
     *
     * @var array
     */
    protected $guarded = ['id', 'created_at', 'deleted_at'];

    /**
     * 软删除应该被调整为日期的属性
     * [$dates description]
     * @var [type]
     */
    protected $dates = [
        'created_at', 'updated_at', 'deleted_at'
    ];


    /**
     * 获取
     * @param int $region_id
     * @param string $select
     * @return array
     */
    public static function getRegionInfoById(int $region_id = 0, string $select = '*'): array
    {

        $region_info = self::where('status', 1)
            ->selectRaw($select)
            ->find($region_id);

        if (isset($region_info) && !empty($region_info)) {

            return $region_info->toArray();

        } else {

            return [];

        }

    }
}
